<?php
/**
 * Created by b17
 * 2/29/12 8:59 PM
 */

namespace Managers\Mailer;

class Subscribe extends Mail
{
    /**
     * @var \Catalog\Subscribers
     */
    private $_data;

    /**
     * @var \Managers\Subscribers
     */
    private $_manager;

    public function __construct(\Catalog\Subscribers $data)
    {
        parent::__construct();
        $this->_data = $data;
        $this->_manager = new \Managers\Subscribers();

        $this->setSubject('Subscribing');

        $this->_initMessage();
    }

    private function _initMessage()
    {
        $this->addTo($this->_data->getEmail());
        $this->setBodyHtml($this->_getContent());
    }

    private function _getUrl()
    {
        $token = $this->_manager->getToken($this->_data);
        $url = $this->_getBaseUrl() . "subscribe/remove/token/" . $token;
        return $url;
    }

    private function _getContent()
    {
        $view = new \Zend_View();
        $view->setScriptPath($this->_getScriptPath());
        $view->url = $this->_getUrl();
        $content = $view->render('/mail/subscribe.phtml');
        return $content;
    }
}
